
window.list = {};
list = function(data, container, paginationcontainer) {
	this.data = data;
	this.totalSize = data.length;
	this.element_ = container;
	this.pagination = new pagination(paginationcontainer);
	this.pagination.renderPager(this.totalSize, 1)
	this.pageSize = this.pagination.getPageSize();
	this.renderTable(this.data.slice(0, 20));
	this.bindEvent();
};

list.prototype.bindEvent = function() {
	$(this.pagination).listen('pagechange', this.handlePageChange, this)
}
list.prototype.handlePageChange = function(e) {
	var pageNo = e.pageNo;
	var start = this.pageSize * pageNo;
	this.renderTable(this.data.slice(start, start + this.pageSize));

}

list.prototype.renderTable = function(data) {
	var html = [];
	for (var i = 0; i < data.length; i++) {
		html.push('<tr>');
		html.push('<td>'+data[i].date+'</td>');
		html.push('<td>'+data[i].unit+'</td>');
		html.push('<td>'+data[i].per+'</td>');
		html.push('</tr>');
	};
	this.element_.html(html.join(''));
};

